`timescale 1ns/100ps

module video_timming_detect_tb;

parameter SYSCLK_PERIOD = 10;

reg SYSCLK;
reg nRESET;
reg fsync_in;
reg enable_fsync;
reg [15:0] h_total;
reg [15:0] v_total;
reg [15:0] h_active;
reg [15:0] h_active_front;
reg [15:0] h_active_front_sync;
reg [15:0] v_active;
reg [15:0] v_active_front;
reg [15:0] v_active_front_sync;

reg second;

initial
begin
	SYSCLK = 0;
	nRESET = 0;
	fsync_in = 0;
	enable_fsync = 1;
	h_total = 20-1;
	v_total = 12-1;
	h_active = 12-1;
	h_active_front = 14-1;
	h_active_front_sync = 16-1;
	v_active = 8-1;
	v_active_front = 10-1;
	v_active_front_sync = 12-1;
	second = 0;
end


/*iverilog */
initial
begin            
    $dumpfile("video_timming_detect.vcd");   //生成的vcd文件名称
    $dumpvars(0, video_timming_detect_tb);    //tb模块名称
end
/*iverilog */

initial

begin
	#(SYSCLK_PERIOD * 2 )
        nRESET = 1'b1;
	#2000
		fsync_in = 1;
	#10
		fsync_in = 0;
	#190
		fsync_in = 1;
	#10
		fsync_in = 0;
	#2400
		fsync_in = 1;
	#10
		fsync_in = 0;
	#2380
		fsync_in = 1;
	#10
		fsync_in = 0;
	#2410
		fsync_in = 1;
	#10
		fsync_in = 0;
	
	#4000
		$finish;
end

always @(SYSCLK)
begin
	#(SYSCLK_PERIOD / 2.0) SYSCLK <= !SYSCLK;
end

wire data_enable;
wire hsync;
wire vsync;


video_timming video_timming_0 (
	// input
	.clk(SYSCLK),
	.rst_n(nRESET),
	.fsync_in(fsync_in),
	.enable_fsync(enable_fsync),
	.h_total(h_total),
	.v_total(v_total),
	.h_active(h_active),
	.h_active_front(h_active_front),
	.h_active_front_sync(h_active_front_sync),
	.v_active(v_active),
	.v_active_front(v_active_front),
	.v_active_front_sync(v_active_front_sync),
	
	// output
	.hsync(hsync),
	.vsync(vsync),
	.data_enable(data_enable),
	.fsync_out(fsync_out)	

);




video_timming_detect video_timming_detect_0(
	// input
	.rst_n(nRESET),
	.clk(SYSCLK),
	.hsync(hsync),
	.vsync(vsync),
	.data_enable(data_enable),
	.second(second),
	
	// output
	.h_total(detect_h_total),
	.v_total(detect_v_total),
	.h_sync(detect_h_sync),
	.h_sync_back(detect_h_sync),
	.h_sync_back_active(detect_h_sync_back_active),
	.v_sync(detect_v_sync),
	.v_sync_back(detect_v_sync_back),
	.v_sync_back_active(detect_v_sync_back_active),
	.total_pixel(detcet_total_pixel)
);

endmodule